package com.wyz.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wyz.dto.StudentClassDTO;
import com.wyz.entity.ClassEntity;
import com.wyz.entity.StudentEntity;
import com.wyz.mapper.ClassMapper;
import com.wyz.mapper.StudentClassMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wk
 * @desc
 * @date 2024/12/23 11:20
 */
@Service
public class ClassService {
    @Resource
    private ClassMapper classMapper;
    @Resource
    private StudentClassMapper studentClassMapper;
    //分页查询班级信息
    public IPage<ClassEntity> getStudentListByPage(int currentPage) {
        IPage<ClassEntity> page = new Page<>(currentPage,5);
        IPage<ClassEntity> classListPage = classMapper.selectPage(page,null);
        return classListPage;
    }

    public boolean addClass(ClassEntity classEntity) {
        return classMapper.insert(classEntity)>0;
    }

    public ClassEntity queryClassById(Integer classId) {
        return classMapper.selectById(classId);
    }

    public boolean updateClass(ClassEntity classEntity) {
        return classMapper.updateById(classEntity)>0;
    }

    public boolean deleteClass(Integer classId) {
        return classMapper.deleteById(classId)>0;
    }


    public List<StudentClassDTO> queryStudentAndClassName(String className) {
        return studentClassMapper.queryStudentAndClassName(className);
    }


}
